package com;

import org.junit.Test;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.web.util.matcher.RegexRequestMatcher;
import org.springframework.security.web.util.matcher.RequestMatcher;

import javax.servlet.http.HttpServletRequest;
import java.util.regex.Pattern;

/**
 * Created by sola on 2018/1/24.
 */
@Deprecated
@Configuration
public class CsrfSecurityRequestMatcher implements RequestMatcher {
    private Pattern allowedMethods = Pattern.compile("^(GET|HEAD|TRACE|OPTIONS)$");
    private RegexRequestMatcher unprotectedMatcher = new RegexRequestMatcher("/druid/.*", null);

    @Override
    public boolean matches(HttpServletRequest request) {
        if(allowedMethods.matcher(request.getMethod()).matches()){
            return false;
        }
        final Boolean result =!unprotectedMatcher.matches(request);
        return result;
    }
    @Test
    public void Test(){
        boolean s=(Pattern.compile("/druid/.*")).matcher("/druid/sub").matches();
        System.out.println(s);
    }
}